package com.xuyifeng.callfilter;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;

public class ACallFilterActivity extends Activity {
	SharedPreferences m_prefs;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_view);
          
    	m_prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    	
        Button btnList = (Button)findViewById(R.id.btn_lists);
        btnList.setOnClickListener(new View.OnClickListener() {
        	
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(ACallFilterActivity.this, FilterListsActivity.class);
				startActivity(intent);
			}
		});
 
        Button btnFilter = (Button)findViewById(R.id.btn_filter_method);
        btnFilter.setOnClickListener(new View.OnClickListener() {
        	
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(ACallFilterActivity.this, FilterMethodActivity.class);
				startActivity(intent);
			}
		});
      
        Button btnLog = (Button)findViewById(R.id.btn_log_list);
        btnLog.setOnClickListener(new View.OnClickListener() {
        	
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(ACallFilterActivity.this, LogListActivity.class);
				startActivity(intent);
			}
		});
        
        setCheckBoxCallBack(R.id.chk_enable_filter, Settings.KEY_ENABLE_FILTER, true);
        setCheckBoxCallBack(R.id.chk_clear_call_log, Settings.KEY_CLEAR_CALL_LOG, false);
    }
    
    void setCheckBoxCallBack(int id, final String key, boolean defVal) {
    	CheckBox chk = (CheckBox)findViewById(id);
        chk.setChecked(m_prefs.getBoolean(key, defVal));
        chk.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				CheckBox chk = (CheckBox) v;
				SharedPreferences.Editor editor = m_prefs.edit();
				editor.putBoolean(key, chk.isChecked());
				editor.commit();
			}
		});
    }
}